Skip to content

GH-144688: Fix refleaks in JIT when optimization fails#145420

Open
markshannon wants to merge 1 commit intopython:mainfrom
markshannon:fix-jit-refleak
Open

GH-144688: Fix refleaks in JIT when optimization fails#145420
markshannon wants to merge 1 commit intopython:mainfrom
markshannon:fix-jit-refleak

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Mar 2, 2026

Make sure that we clear references to recorded objects when cleaning up JIT.

@markshannon
Copy link
Member Author

Skipping news as this bug didn't make it into a release

// Clear all recorded values
_PyJitUopBuffer *buffer = &tracer->code_buffer;
for (_PyUOpInstruction *inst = buffer->start; inst < buffer->next; inst++) {
if (_PyUop_Flags[inst->opcode] & HAS_RECORDS_VALUE_FLAG) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means you can remove

        else if (_PyUop_Flags[opcode] & HAS_RECORDS_VALUE_FLAG) {
            Py_XDECREF((PyObject *)(uintptr_t)buffer[pc].operand0);
            buffer[pc].opcode = _NOP;
        }

in optimizer.c to avoid double work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do double work: https://github.com/python/cpython/pull/145420/changes#diff-de09f74c4306be5ef0284d665091976873569094d645a35b48467ea2a11d67f7R1531 and it is faster to leave the cleanup in the fixup pass as we have to do that pass anyway in the normal, non-error case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants